#!/usr/bin/env python
# -*- coding:utf-8 -*-
#
#-------------------------------------------------------------------------------
# Name:        module1
# Purpose:
#
# Author:      shoo
#
# Created:     12/06/2011
# Copyright:   (c) shoo 2011
# Licence:     <your licence>
#-------------------------------------------------------------------------------
import inline_img
from google.appengine.ext import webapp
from google.appengine.ext.webapp import util

# デコメ・絵文字画像をhttpで取得する
# /img?k=[キー文字列]
class ImgHandler(webapp.RequestHandler):
    def get(self):
        key = self.request.get("k")
        if not key:
            self.error(400) #Bad Request
            return

        img = inline_img.Image.get_by_key_name(key)
        if not img:
            self.error(404) #Not Found
            return

        self.response.headers['Content-Type'] = img.content_type
        self.response.out.write(img.data)
        return

def main():
    application = webapp.WSGIApplication([('/img', ImgHandler)],
                                         debug=True)
    util.run_wsgi_app(application)

if __name__ == '__main__':
    main()
